//
// Created by hss on 2017/8/14.
//

#include "fileutil.h"

#define NELEM(x) ((jint) (sizeof(x) / sizeof((x)[0])))




    JNIEXPORT void JNICALL
    native_diff(JNIEnv *env, jobject instance, jstring path_,
                                             jstring pattern_path_, jint fule_num) {
        const char *path = env->GetStringUTFChars(path_, 0);
        const char *pattern_path = env->GetStringUTFChars(pattern_path_, 0);
        LOGD("jni begin 动态注册方法");
        // TODO
        int x = addTest(56,20);
        LOGD("x= %d",x);
        env->ReleaseStringUTFChars(path_, path);
        env->ReleaseStringUTFChars(pattern_path_, pattern_path);
    }



static const JNINativeMethod gMethods[] = {
        {
                 "diff", "(Ljava/lang/String;Ljava/lang/String;I)V",(void*)native_diff
        }
};


static  int registerNatives(JNIEnv * env){
    jclass  jclass1;
    jclass1 = env->FindClass("com/hss/danymicloadso/FileUtil");

    if (jclass1 == NULL){
        LOGD("FindClass(\"com/hss/danymicloadso/FileUtil\")  == NULL");
        return JNI_FALSE;
    }
    if (env->RegisterNatives(jclass1,gMethods,NELEM(gMethods))< 0){
        LOGD("RegisterNatives < 0");
        return JNI_FALSE;
    }

    return JNI_TRUE;
}

JNIEXPORT  jint JNI_OnLoad(JavaVM * vm, void * reserved){
    LOGD("jni onload begin");
    JNIEnv * env = NULL;
    jint  result= -1;
    if ((*vm).GetEnv((void **)&env, JNI_VERSION_1_4) != JNI_OK){
        LOGD("GetEnv error");
        return -1;
    }
    assert("env != null");
    registerNatives(env);
    return  JNI_VERSION_1_4;
}